package com.api.shopapi.mapper;

import com.api.shopapi.entity.CommandCenter;
import com.api.shopapi.entity.PracticeSite;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommandCenterMapper {


    @Insert("insert into command_center " +
            "(" +
            "CommandCenterCode," +
            "UserCode," +
            "Address," +
            "CreateTime," +
            "GovernmentCode" +
            ") " +
            "values " +
            "(" +
            "#{commandCenter.CommandCenterCode}," +
            "#{commandCenter.UserCode}," +
            "#{commandCenter.Address}," +
            "#{commandCenter.CreateTime}," +
            "#{commandCenter.GovernmentCode}" +
            ")" )
    int insert(@Param("commandCenter") CommandCenter commandCenter);


    @Delete("delete from command_center where commandCenterCode=#{commandCenterCode}")
    int delete(@Param("commandCenterCode") String commandCenterCode);


    @Update("update command_center set " +
            " Address=#{commandCenter.Address}" +
            " where commandCenterCode=#{commandCenter.commandCenterCode}")
    int update(@Param("commandCenter") CommandCenter commandCenter);


    @Select("select * from command_center where commandCenterCode=#{commandCenterCode} limit 1")
    CommandCenter getByCommandCenterCode(@Param("commandCenterCode") String commandCenterCode);


    @Select("select * from command_center where userCode=#{userCode} limit 1")
    CommandCenter getByUserCode(@Param("userCode") String userCode);


    @Select("<script>" +
            "select cc.CommandCenterCode from command_center cc join user u on cc.UserCode = u.UserCode" +
            " where cc.governmentCode=#{governmentCode}" +
            "<if test ='status != -1 '>" +
            " and u.Status = #{status} " +
            "</if>" +
            " order by cc.CreateTime desc" +
            "</script>")
    List<CommandCenter> ListByGovernmentCode(@Param("governmentCode") String governmentCode,
                                            @Param("status") int status);


}
